<!-- 放箱公司管理 -->
<template>
  <div class="box-company">
    <!-- 查询 -->
    <el-row :gutter="15">
      <el-col :span="19">
        <el-form v-model="formData" size="mini" :inline="true" class="demo-form-inline">
          <el-form-item label="客户名称" label-width="70px">
            <el-input v-model="formData.fullName" @keyup.enter.native="getPutBoxList(1, 15)"></el-input>
          </el-form-item>
          <el-form-item label="公司联系人" label-width="90px">
            <el-input v-model="formData.linkMan" @keyup.enter.native="getPutBoxList(1, 15)"></el-input>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="5">
        <div style="display: flex; justify-content: flex-end; height: 29px;">
          <el-button size="mini" type="success" @click="newBoxcom">添加放箱公司</el-button>
          <el-button type="primary" size="mini" @click="getPutBoxList(1, 15)">搜索</el-button>
          <el-button size="mini" @click="clearInfo">清空</el-button>
        </div>
      </el-col>
    </el-row>
    <!-- 表格 -->
    <el-table
      v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(255, 255, 255, 0.5)"
      border
      :data="tableData"
      style="width: 100%; overflow-x: auto;">
      <el-table-column
        align="center"
        width="150px"
        :show-overflow-tooltip="true"
        label="公司全称">
        <template slot-scope="scope">
          {{scope.row.CompanyName}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        width="100px"
        label="手机号">
        <template slot-scope="scope">
          {{scope.row.Mobile1}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :show-overflow-tooltip="true"
        label="账号">
        <template slot-scope="scope">
          {{scope.row.NickName}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="联系人">
        <template slot-scope="scope">
          {{scope.row.linkMan}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        width="200"
        :show-overflow-tooltip="true"
        label="公司地址">
        <template slot-scope="scope">
          {{scope.row.Address}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        width="100"
        label="客户名称">
        <template slot-scope="scope">
          {{scope.row.FullName}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        width="100px"
        label="联系电话">
        <template slot-scope="scope">
          {{scope.row.Phone1}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="QQ">
        <template slot-scope="scope">
          {{scope.row.QQ}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="传真">
        <template slot-scope="scope">
          {{scope.row.fax}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="上港代码">
        <template slot-scope="scope">
          {{scope.row.protocolCode}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="助记码">
        <template slot-scope="scope">
          {{scope.row.ZJM}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        width="140">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="isSure(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="salesman-man-pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageNo"
        :page-sizes="[15, 20, 30]"
        :page-size="number"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <new-boxcom-dialog></new-boxcom-dialog>
  </div>
</template>

<script>
import NewBoxcomDialog from './dialog/NewBoxcomDialog.vue'
import { getPutBoxList, deletecarManagerInfo } from './api/customerManagement'
export default {
  components: {
    NewBoxcomDialog
  },
  data () {
    return {
      tableData: [],
      uploadData: {},
      editObj: {},
      loading: true,
      pageNo: 1,
      number: 15,
      total: 0,
      formData: {
        fullName: '',
        linkMan: ''
      }
    }
  },
  mounted () {
    this.getPutBoxList(1, 15)
  },
  methods: {
    newBoxcom () {
      this.$store.commit('show_new_boxcom_dialog')
    },
    // 封装的调用父组件方法
    parentName () {
      this.getPutBoxList(this.pageNo, this.number)
    },
    // 获取表格数据
    async getPutBoxList (pg, nb) {
      this.loading = true
      const res = await getPutBoxList({
        fullName: this.formData.fullName,
        linkMan: this.formData.linkMan,
        page: pg,
        num: nb
      })
      if (res.status === 200) {
        this.tableData = res.data
        this.total = res.dataCount
        this.loading = false
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
        this.loading = false
      }
    },
    isSure (row) {
      this.$confirm(' 是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteBoxman(row)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
        return false
      })
    },
    // 删除用箱人
    async deleteBoxman (row) {
      const res = await deletecarManagerInfo({
        customerId: row.UserId
      })
      if (res.status === 200) {
        this.$notify({
          title: '成功',
          message: res.msg,
          type: 'success'
        })
        this.getPutBoxList(this.pageNo, this.number)
      } else {
        this.$notify({
          title: '错误',
          message: res.msg,
          type: 'error'
        })
      }
    },
    clearInfo () {
      this.formData.fullName = ''
      this.formData.linkMan = ''
    },
    handleCurrentChange (val) {
      this.getPutBoxList(val, this.number)
      this.pageNo = val
    },
    // 每页条数
    handleSizeChange (val) {
      this.getPutBoxList(this.pageNo, val)
      this.number = val
    }
  }
}
</script>

<style lang="less">
  .fitler{
    .el-tag{
      cursor: pointer;
    }
  }
  .salesman-man-pagination {
    width: 100%;
    margin: 0 auto;
    margin-top: 10px;
  }
</style>
